# -*- ecoding: utf-8 -*-
# @ModuleName: file_load
# @Author: wangwei 
# @Time: 2023/10/20 10:41
import pandas
import yaml

from get_project_path import project_path


def read_excel(filename,shetname):
    read=pandas.read_excel(f"{project_path()}{filename}",sheet_name=shetname,keep_default_na=False,engine='openpyxl')
    cols=read.shape[0]
    rows=read.shape[1]
    print(cols)
    print(rows)
    data_list=[]
    for col in range(cols):
        data_line=[]
        for row in range(rows):
            line=read.iloc[col,row]
            data_line.append(line)
        data_list.append(data_line)
    return data_list




def read_yaml(filename):
    with open(f"{project_path()}{filename}",mode='r',encoding='utf-8') as f:
        content=yaml.load(f,Loader=yaml.FullLoader)
        return content


def write_yaml(content,filename):
    with open(f"{project_path()}{filename}",mode='w',encoding='utf-8') as f:
        yaml.dump(content,f,Dumper=yaml.Dumper,allow_unicode='utf-8')


if __name__ == '__main__':
    # print(read_excel("/data/mtxshop_testdata.xlsx", '添加购物车测试数据'))
    # print(read_yaml("/data/mtxshop_testdata.yml"))
    # conten=read_yaml("/data/mtxshop_testdata.yml")
    # write_yaml(conten,'/config/test.yml')
    content = read_yaml("/config/common.yml")
    print(content)
    username = read_yaml("/config/common.yml").get('buyerName')[0]
    password = read_yaml("/config/common.yml").get('buyerPassword')[0]
    print(username)
    print(password)